#Copyright (c) 2025, Alibaba Cloud and its affiliates;
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at

#   http://www.apache.org/licenses/LICENSE-2.0

#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.

import os
import multiprocessing
import configparser

MAX_DEFAULT_WORKERS = 12

def get_workers():
    worker_number = multiprocessing.cpu_count()*2+1
    if worker_number > MAX_DEFAULT_WORKERS:
        worker_number = MAX_DEFAULT_WORKERS
    return worker_number

def get_server_version(chdir):
    server_config = configparser.ConfigParser()
    conf_path = os.path.join(chdir, './config/fce_server.conf')
    server_config.read(conf_path)
    return server_config.get('Common', 'Version')

bind = '0.0.0.0:12021'
backlog = 512
chdir = os.path.dirname(os.path.abspath(__file__))
timeout = 50
worker_class = 'sync'
workers = get_workers()
threads = 1
loglevel = 'info'
access_log_format = '%(t)s %(p)s %(h)s %(u)s "%(r)s" %(i)s %(s)s %(M)s %(b)s %(f)s" "%(a)s" "fce server: "' + get_server_version(chdir)
accesslog = os.path.join(chdir, "./logs/server_access.log")
errorlog = os.path.join(chdir, "./logs/server_error.log")
#certfile = "./config/server.crt"
#keyfile = "./config/server.key"
